How to shorthand all these if checks and reassigns